package rules;

import managers.FeatureManager;

import org.jdom2.Element;

import components.Phrase;
import features.Feature;
import features.FeatureList;

public class RuleInputPhrase extends Phrase {

	private int tag;
	private boolean isOptional;
	
	public RuleInputPhrase(Element componentElement) {
		super(componentElement);
	}
	
	public void setFeature(Feature newFeature){ // ALLOWS DUPLICATION
		featureList.getFeatureList().add(newFeature);
	}
	
	protected void setDefaults() { // NO DEFAULTS SINCE LHS SIDE SIYA
		this.featureList = new FeatureList();
	}

	public int getTag(){
		return tag;
	}
	
	public void setTag(int tag){
		this.tag = tag;
	}

	public boolean isOptional(){
		return isOptional;
	}
	public void setOptional(boolean isOptional){
		this.isOptional = isOptional;
	}
	
	public Element generateXMLElement() {
		Element xmlElement = new Element("component");
		xmlElement.setAttribute(ATTRIBUTE_NAME, name);
		if(isOptional)
			xmlElement.setAttribute("isOptional", Boolean.toString(isOptional));
		if(tag != -1)
			xmlElement.setAttribute("tag", Integer.toString(tag));
		if(featureList != null){
			Element featuresElement = featureList.generateXMLElementForComponent(name);
			if(featuresElement != null)
				xmlElement.addContent(featuresElement);
		}
		addAdditionalXMLContent(xmlElement);
		return xmlElement;
	}
}
